<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>听说--登录</title>
    <link rel="icon" href="${request.contextPath!}/css/images/favicon.ico">
    <link rel="stylesheet" href="${request.contextPath!}/css/login.css">
    <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
    <link rel='stylesheet prefetch' href='https://fonts.googleapis.com/icon?family=Material+Icons'>

    <style type="text/css">
        body { background:url(https://static.acg12.com/uploads/2016/09/9fd75c783ecc5c8afe958820a56ea578.jpg) center bottom no-repeat fixed;
            background-size: 100%;}
    </style>

  
</head>

<body>

<form action="/file/upload_file" method="post" enctype="multipart/form-data">
    文件<input type="file" name="index_image" id="file_image"/>
    <input type="button" id="file_btn" value="上传"/>
</form>



<div class="cotn_principal">
    <div class="cont_centrar">
        <div class="cont_login">
            <div class="cont_info_log_sign_up">
                <div class="col_md_login">
                    <div class="cont_ba_opcitiy">
                        <h2>登  录</h2>
                        <p>已有账号？那就来登录吧！</p>
                        <button class="btn_login" onClick="cambiar_login()">登  录</button>
                    </div>
                </div>
                <div class="col_md_sign_up">
                    <div class="cont_ba_opcitiy">
                        <h2>注  册</h2>
                        <p>没有账号？那不妨先来注册吧！</p>
                        <button class="btn_sign_up" onClick="cambiar_sign_up()">注  册</button>
                    </div>
                </div>
            </div>
            <div class="cont_back_info">
                <div class="cont_img_back_grey"> <img src="https://static.acg12.com/uploads/2017/05/8a07c090faa01c4a6603f5358019c4a5-448x600.jpg" alt="" /> </div>
            </div>
            <div class="cont_forms" >
                <div class="cont_img_back_"> <img src="https://static.acg12.com/uploads/2017/05/8a07c090faa01c4a6603f5358019c4a5-448x600.jpg" alt="" /> </div>
                <div class="cont_form_login"> <a href="#" onClick="ocultar_login_sign_up()" ><i class="material-icons">&#xE5C4;</i></a>
                    <h2>登  录</h2>
                    <input type="hidden" id="referer" value="${referer_url!}" />
                    <input type="text" placeholder="请输入邮箱..." name="login_email" id="login_email"/>
                    <input type="password" placeholder="请输入密码..." name="login_pwd" id="login_pwd"/>
                    <button id="login_btn" class="btn_login">登  录</button>
                </div>
                <div class="cont_form_sign_up"> <a href="#" onClick="ocultar_login_sign_up()"><i class="material-icons">&#xE5C4;</i></a>
                    <h2>注  册</h2>
                    <input type="text" placeholder="请输入邮箱..." name="rei_email" id="rei_email"/>
                    <input type="password" placeholder="请输入密码..." name="rei_pwd" id="rei_pwd"/>
                    <input type="password" placeholder="请再次输入密码..." name="rei_pwd2" id="rei_pwd2"/>
                    <button id="signup" class="btn_sign_up">注  册</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${request.contextPath!}/js/login.js"></script>
<script type='text/javascript' src='//cdn.bootcss.com/jquery/1.12.3/jquery.min.js'></script>
<script type="text/javascript" src="${request.contextPath!}/layer/layer.js"></script>
<script type="text/javascript" src="${request.contextPath!}/js/easy.ajax.js"></script>
<script type="text/javascript">
    $(function () {
        $("#signup").click(function(){
            if($("#rei_email").val() == ""){
                layer.tips('邮箱不能为空', '#rei_email');
                return;
            }
            if($("#rei_pwd").val() == ""){
                layer.tips('密码不能为空', '#rei_pwd');
                return;
            }
            if($("#rei_pwd").val().length < 6){
                layer.tips('密码长度不能小于6哦', '#rei_pwd');
                return;
            }
            if($("#rei_pwd2").val() == ""){
                layer.tips('需要再一次输入密码哦', '#rei_pwd2');
                return;
            }
            if($("#rei_pwd2").val() != $("#rei_pwd2").val()){
                layer.tips('两次输入密码不一致哦', '#rei_pwd2');
                return;
            }
            var index;
            $.ajax({
                type:"post",
                dataType:"text",
                url:"${request.contextPath!}/signup",
                data:{rei_email:$("#rei_email").val(),
                    rei_pwd:$("#rei_pwd").val(),
                    rei_pwd2:$("#rei_pwd2").val()},
                async:true,
                traditional: true,
                beforeSend: function(){
                    index = layer.load(0, {shade: false});
                },
                success:function(data){
                    if(data == "success"){
                        layer.close(index);
                        layer.msg('注册成功', {icon: 1});
                        window.location.href = document.referrer;
                    }else{
                        layer.close(index);
                        layer.msg('注册失败', {icon: 2});
                    }
                }
            })
        });

        $("#login_btn").click(function(){
            if($("#login_email").val() == ""){
                layer.tips('邮箱不能为空', '#login_email');
                return;
            }
            if($("#login_pwd").val() == ""){
                layer.tips('密码不能为空', '#login_pwd');
                return;
            }
            $.ajax({
                type:"post",
                dataType:"json",
                url:"${request.contextPath!}/login",
                data:{login_email:$("#login_email").val(),
                    login_pwd:$("#login_pwd").val(),
                    referfer_url:$("#referer").val()},
                async:true,
                traditional: true,
                success:function(result){
                    if(result.success == "1"){
//                        history.go(-1);
//                        window.location.reload();
                        window.location.href = document.referrer;
                    }else{
                        layer.msg('登录失败', {icon: 2});
                    }
                }
            })
        });

        $('#file_btn').click(function() {
            var file = $("#file_image").get(0).files[0];
            var fileData = new FormData();
            var index = layer.load(0, {shade: false});
            fileData.append("index_image", file);
            EasyAjax.upload_file({
                    url: "/file/upload_file_for_upyun",
                    data: fileData
                },
                function (data) {
                    if (data.success) {
                        layer.close(index);
                        alert("上传成功");
                    }
                });
        });


    })
</script>

</body>
</html>
